<?php

namespace app\controllers;

use app\librarys\BaseController;
use app\models\ApiExceptionLog;
use app\models\ApiOperateLog;
use app\models\MallExceptionLog;
use app\models\MallOperateLog;
use app\models\ManagerExceptionLog;
use app\models\ManagerOperateLog;
use yii\data\Pagination;

class LogRecordController extends BaseController
{
    public function actionManagerOperateLog()
    {
        $request = \Yii::$app->request;
        $controllerId = $request->get('controllerId');
        $actionId = $request->get('actionId');
        $durationTime = $request->get('durationTime');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => ManagerOperateLog::getCount($controllerId, $actionId, $durationTime, $startTime, $endTime),
        ]);

        $records = ManagerOperateLog::getList($pagination->page, $pagination->pageSize, $controllerId, $actionId, $durationTime, $startTime, $endTime);

        return $this->render('manager-operate-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'controllerId' => $controllerId,
                'actionId' => $actionId,
                'durationTime' => $durationTime,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionManagerOperateLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = ManagerOperateLog::getById($logId);
        return $this->renderPartial('manager-operate-log-partial', ['log' => $log]);
    }

    public function actionManagerExceptionLog()
    {
        $request = \Yii::$app->request;
        $controllerId = $request->get('controllerId');
        $actionId = $request->get('actionId');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => ManagerExceptionLog::getCount($controllerId, $actionId, $startTime, $endTime),
        ]);

        $records = ManagerExceptionLog::getList($pagination->page, $pagination->pageSize, $controllerId, $actionId, $startTime, $endTime);

        return $this->render('manager-exception-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'controllerId' => $controllerId,
                'actionId' => $actionId,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionManagerExceptionLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = ManagerExceptionLog::getById($logId);
        return $this->renderPartial('manager-exception-log-partial', ['log' => $log]);
    }


    public function actionMallOperateLog()
    {
        $request = \Yii::$app->request;
        $actionId = $request->get('actionId');
        $durationTime = $request->get('durationTime');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => MallOperateLog::getCount($actionId, $durationTime, $startTime, $endTime),
        ]);

        $records = MallOperateLog::getList($pagination->page, $pagination->pageSize, $actionId, $durationTime, $startTime, $endTime);

        return $this->render('mall-operate-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'actionId' => $actionId,
                'durationTime' => $durationTime,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionMallOperateLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = MallOperateLog::getById($logId);
        return $this->renderPartial('mall-operate-log-partial', ['log' => $log]);
    }

    public function actionMallExceptionLog()
    {
        $request = \Yii::$app->request;
        $actionId = $request->get('actionId');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');
        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => MallExceptionLog::getCount($actionId, $startTime, $endTime),
        ]);

        $records = MallExceptionLog::getList($pagination->page, $pagination->pageSize, $actionId, $startTime, $endTime);

        return $this->render('mall-exception-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'actionId' => $actionId,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionMallExceptionLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = MallExceptionLog::getById($logId);
        return $this->renderPartial('mall-exception-log-partial', ['log' => $log]);
    }


    ///////////////////////////////////////////////////////////////////////////////////////


    public function actionApiOperateLog()
    {
        $request = \Yii::$app->request;
        $actionId = $request->get('actionId');
        $account = $request->get('account');
        $durationTime = $request->get('durationTime');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => ApiOperateLog::getCount($actionId, $account, $durationTime, $startTime, $endTime),
        ]);

        $records = ApiOperateLog::getList($pagination->page, $pagination->pageSize, $actionId, $account, $durationTime, $startTime, $endTime);

        return $this->render('api-operate-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'actionId' => $actionId,
                'account' => $account,
                'durationTime' => $durationTime,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionApiOperateLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = ApiOperateLog::getById($logId);
        return $this->renderPartial('api-operate-log-partial', ['log' => $log]);
    }

    public function actionApiExceptionLog()
    {
        $request = \Yii::$app->request;
        $actionId = $request->get('actionId');
        $account = $request->get('account');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');
        $pagination = new Pagination([
            'defaultPageSize' => 10,
            'totalCount' => ApiExceptionLog::getCount($actionId, $account, $startTime, $endTime),
        ]);

        $records = ApiExceptionLog::getList($pagination->page, $pagination->pageSize, $actionId, $account, $startTime, $endTime);

        return $this->render('api-exception-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'actionId' => $actionId,
                'account' => $account,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionApiExceptionLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = ApiExceptionLog::getById($logId);
        return $this->renderPartial('api-exception-log-partial', ['log' => $log]);
    }


}